import java.util.ArrayList;

public class Dragon extends Piece {
	/*
	 * 8   - - x - - - - - x - - -    
	 * 7   - - - x - - - x - - - -    
	 * 6   - - - - x x x - - - - -    
	 * 5   - - - - x R x - - - - -    
	 * 4   - - - - x x x - - - - -      SKY (3)
	 * 3   - - - x - - - x - - - -    
	 * 2   - - x - - - - - x - - -    
	 * 1   - x - - - - - - - x - -    
	 * 
	 * 8   - - - - - - - - - - - -    
	 * 7   - - - - - - - - - - - -    
	 * 6   - - - - - a - - - - - -   
	 * 5   - - - - a a a - - - - -    
	 * 4   - - - - - a - - - - - -      EARTH (2)
	 * 3   - - - - - - - - - - - -    
	 * 2   - - - - - - - - - - - -    
	 * 1   - - - - - - - - - - - -    
	 *	   a b c d e f g h i j k l
	 * The Dragon stays on the SkyBoard. It also has a special "capture from afar" move, where
	 * it captures one of the Pieces below it without moving to take that Piece's Square. It
	 * cannot do anything else in the same turn that it "captures from afar."
	 */
	
	public Dragon(int s) {
		super(s);
	}

	protected ArrayList<Square> getAvailableMoves() {
		moves.clear();
		for(int i = 0; i < 4; i++) {
			moves.add(getSquare().getFarSquare(Square.NORTH + 90 * i, 1));
		}
		for(int i = 1; i < 8; i++) {
			moves.add(getSquare().getFarSquare(Square.NORTHEAST, i));
			if (moves.get(moves.size() - 1).isOccupied()){
				i += 8;
			}
		}
		for(int i = 1; i < 8; i++) {
			moves.add(getSquare().getFarSquare(Square.SOUTHEAST, i));
			if (moves.get(moves.size() - 1).isOccupied()){
				i += 8;
			}
		}
		for(int i = 1; i < 8; i++) {
			moves.add(getSquare().getFarSquare(Square.SOUTHWEST, i));
			if (moves.get(moves.size() - 1).isOccupied()){
				i += 8;
			}
		}
		for(int i = 1; i < 8; i--) {
			moves.add(getSquare().getFarSquare(Square.NORTHWEST, i));
			if (moves.get(moves.size() - 1).isOccupied()){
				i += 8;
			}
		}
		System.out.println(moves);
		return moves;
	}
	
	protected ArrayList<Square> getAvailableCapts() {
		capts.clear();
		capts.add(getSquare().getFarSquare(Square.DOWN, 1));
		for(int i = 0; i < 4; i++) {
			capts.add(getSquare().getFarSquare(Square.DOWN, 1).getFarSquare(Square.NORTH + 90 * i, 1));
		}
		return capts;
	}
	
	@Override
	public boolean captTo(Square dest){
		if(canCaptTo(dest)){
			if (dest.getBoard().getLevel() == 2){
				dest.getPiece().removeSelfFromBoard();
				return true;
			}
			setSquare(dest);
			//Insert code to move the "physical" piece to the square.
			return true;
		}
		return false;
	}
	
	public String toString() {
		if(side == 1) {
			return "R";
		} else if(side == 2) {
			return "r";
		} else {
			return "no side";
		}
	}
}
